#ifndef _TARGETBL_CONFIG_H_
#define _TARGETBL_CONFIG_H_

#include "user_global.h"

//typedef unsigned char    bit;
//------------------------------------------------------------------------------
// 设备相关的配置
//------------------------------------------------------------------------------

#define PCB_A1                        1
#define PCB_A2                        2
#define PCB_A3                        3

// PCB版本: 定义转到项目属性中
//#define PCB_VERSION                    PCB_A2


// 写入程序后锁定bootloader程序
#define BL_LOCK_FLASH

// 硬件进入BootLoader模式引脚,
// 如果不使用外部引脚, 注释掉它
#define BL_OVERRIDE_PIN                       !gpio_input_bit_get(SWITCH4_GPIO_Port, SWITCH4_Pin)

#define  IO_S1()                              gpio_input_bit_get(SWITCH1_GPIO_Port,SWITCH1_Pin)
#define  IO_S2()                              gpio_input_bit_get(SWITCH2_GPIO_Port,SWITCH2_Pin)
#define  IO_S3()                              gpio_input_bit_get(SWITCH3_GPIO_Port,SWITCH3_Pin)
#define  IO_S4()                              gpio_input_bit_get(SWITCH4_GPIO_Port,SWITCH4_Pin)


// Company-specific product ID
// 0x32 : PCB_A1, 
// 0x33:  PCB_A2
// 0x34 : PCB_A3
#if (PCB_VERSION < PCB_A2)
    #define TGT_PRODUCT_CODE            0x32
#elif (PCB_VERSION == PCB_A2)
    #define TGT_PRODUCT_CODE            0x33
#elif (PCB_VERSION == PCB_A3)
    #define TGT_PRODUCT_CODE            0x34
#else
    #error "TGT_PRODUCT_CODE not defined"
#endif

// flash基址
#define FLASH_BASE_ADDR                 0x08000000

//sig字节大小
#define SIG_SIZE                        0x04

//sig字节偏移地址
//#define FLASH_SIG_OFFSET_ADDRESS        0x00100B
// Total FLASH size in bytes
//#define  TGT_FLASH_SIZE            FLASH_BASE_ADDR + 0x0FFFFF
#define  TGT_FLASH_SIZE                0x10000                                 
// Specify 24-bit linear addresses here (do not use banked 16-bit addresses)
#define  APP_FW_START_ADDR             0x008000                                 

//------------------------------------------------------------------------------
// 不经常改动的配置
//------------------------------------------------------------------------------

// BL Firmware version
#if (PCB_VERSION == PCB_A1)
#define TGT_BL_FW_VERSION_LOW         0x00
#define TGT_BL_FW_VERSION_HIGH        0x01
#elif (PCB_VERSION == PCB_A2)
#define TGT_BL_FW_VERSION_LOW         0x00
#define TGT_BL_FW_VERSION_HIGH        0x02
#elif (PCB_VERSION == PCB_A3)
#else
    #error "TGT_PRODUCT_CODE not defined"
#endif

// 通讯速率
#define BAUDRATE                       115200

// BL Type = UART
#define TGT_BL_TYPE                    0x01

// CRC Type = CRC-16-CCITT
#define TGT_CRC_TYPE                   0x01

// Encryption Type = None
#define TGT_ENCRYPTION_TYPE            0x00

// Flash Page Size Code: 2^9 => 512 bytes
// Number of bytes per flash page
#define TGT_FLASH_PAGE_SIZE_CODE    11

// Note: For serial streams like UART where "packets" are not applicable, the packet size
// should be set to be equal to the BL buffer size.

// BL Comm Protocol Packet Size Code.
// Size of comm protocol's packet size (bytes; should be powers of 2)
// If TGT_BL_BUF_SIZE is 2^n, TGT_BL_BUF_SIZE_CODE is n.
#define TGT_BL_PKT_SIZE_CODE        7

// BL Buffer Size Code.
// Size of bootloader RX buffer (bytes; should be powers of 2)
// If TGT_BL_BUF_SIZE is 2^n, TGT_BL_BUF_SIZE_CODE is n.
#define TGT_BL_BUF_SIZE_CODE        7

// Target Serial Number (for multi-drop buses)
// 0=Disabled; Max: 7
#define DEV_SERIAL_NUMBYTES            0

// ** Ensure a UNIQUE Serial Number for each device on the same bus **
// - These are "don't care" if DEV_SERIAL_NUMBYTES is set to 0.
// - These need not be used if device addressing on a bus is handled
//   at the comm protocol level.
#define TGT_DEVICE_SERIAL0            0x01
#define TGT_DEVICE_SERIAL1            0x00

// 写FLASH的缓冲区起始地址
#define TGT_BUF_START_ADDR            0x8000

#endif // #ifndef _TARGETBL_CONFIG_H_
